package com.btpj.hospital_server.dto;

import com.btpj.hospital_server.entity.PowerAccount;
import com.btpj.hospital_server.entity.PowerRole;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;

@ApiModel(value = "PowerAccountDTO", description = "用户信息封装对象")
@Data
public class PowerAccountDTO implements Serializable {

    @ApiModelProperty("编号")
    private Long id;

    @ApiModelProperty("登录账号")
    private String name;

    @ApiModelProperty("用户权限")
    private List<PowerRole> powerRoles;

    @ApiModelProperty("token")
    private String token;

    private static final long serialVersionUID = 1L;

    /**
     * 将实体转化为接口需要的DTO结构
     *
     * @param powerAccount PowerAccount
     * @return PowerAccountDTO
     */
    public static PowerAccountDTO entity2DTO(PowerAccount powerAccount) {
        PowerAccountDTO powerAccountDTO = new PowerAccountDTO();
        if (powerAccount != null) {
            BeanUtils.copyProperties(powerAccount, powerAccountDTO);
        }
        return powerAccountDTO;
    }
}
